﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Ryder_US_Website.BUS;
using Ryder_US_Website.Utils;

namespace Ryder_US_Website.Presentation.Admin
{
    public partial class CargoStatus_Update : System.Web.UI.Page
    {
        public string id;
        RUS_CargoStatus car = new RUS_CargoStatus();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["RUS_User"] == null)
            {
                Response.Redirect("Login.aspx");
            }
            id = Request.QueryString["id"];
            int temp = Int16.Parse(id);
            car = CargoStatusBUS.GetCargoStatusByID(temp);
            if (!IsPostBack)
            {
                txtTenTTDonHang.Text = car.CargoStatus_name;
                txtMoTa.Text = car.CargoStatus_description;
                rbConSuDung.Checked = (car.CargoStatus_trash == 0);
                rbDaXoa.Checked = !rbConSuDung.Checked;
            }
        }

        protected void btnHuy_Click(object sender, EventArgs e)
        {
            Response.Redirect("CargoStatus_List.aspx");
        }

        protected void btnCapNhat_Click(object sender, EventArgs e)
        {
            RUS_CargoStatus kq = new RUS_CargoStatus();
            car.CargoStatus_name = txtTenTTDonHang.Text;
            car.CargoStatus_description = txtMoTa.Text;
            car.CargoStatus_trash = (rbConSuDung.Checked == true) ? 0 : 1;
            try
            {
                kq = CargoStatusBUS.Update(car.CargoStatus_ID, car.CargoStatus_name, car.CargoStatus_description, car.CargoStatus_trash);

                if (car.CargoStatus_ID.Equals(kq.CargoStatus_ID))
                    Response.Redirect("CargoStatus_List.aspx", false);
                    //Response.Write(UtilHelpers.ShowMessage("Cập nhật thành công"));
                else
                    Response.Write(UtilHelpers.ShowMessage("Cập nhật không thành công"));
            }
            catch(Exception ex)
            {
                Response.Write(UtilHelpers.ShowMessage(ex.Message));
            }
        }
    }
}
